//
//  ContinueInsuranceRootViewController.m
//  CPICApp
//
//  Created by sinosoft on 13-5-7.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "ContinueInsuranceRootViewController.h"
#import "Config.h"
#import "RCAlertViewUtil.h"
#import "NSString+SBJson.h"
#import "NSObject+SBJson.h"
#import "UIImageView+WebCache.h"
#import "IFServiceEvaluation.h"
#import "Appdelegate.h"
#import "SunInsuranceViewController.h"
#import "ApplyInsuranceViewController.h"
#import "InsuranceHistoryViewController.h"
#import "OperationLogView.h"

@interface ContinueInsuranceRootViewController ()

@end

@implementation ContinueInsuranceRootViewController
@synthesize progress,arrData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"我想续保";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"我想续保");
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"InsuranceHistory.png");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"我想续保");
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"InsuranceHistory.png");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"我想续保");
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
        
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"InsuranceHistory.png");
    }
    
    
    ItemCountBusiness=0;
    ItemCountJiaoQiang=0;
    
    //添加UITableview
    TableViewBusiness = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 165) style:UITableViewStyleGrouped];
	TableViewBusiness.delegate = self;
	TableViewBusiness.dataSource = self;
    TableViewBusiness.opaque = NO;
    TableViewBusiness.backgroundView = nil;
    TableViewBusiness.autoresizingMask = UIViewContentModeTop;
    TableViewBusiness.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewBusiness.scrollEnabled=NO;
    [self.view addSubview:TableViewBusiness];
    
    btnInsuranceDetail=[UIButton buttonWithType:UIButtonTypeCustom];
    btnInsuranceDetail.frame=CGRectMake(35, 215, 115, 30);
    [btnInsuranceDetail setImage:[UIImage imageNamed:@"InsDetail@2x.png"] forState:UIControlStateNormal];
    [btnInsuranceDetail addTarget:self action:@selector(InsDetailButtonTap:) forControlEvents:UIControlEventTouchUpInside];
    
    btnContinueInsuance=[UIButton buttonWithType:UIButtonTypeCustom];
    btnContinueInsuance.frame=CGRectMake(179, 215, 115, 30);
    [btnContinueInsuance setImage:[UIImage imageNamed:@"ContinueIns@2x.png"] forState:UIControlStateNormal];
    [btnContinueInsuance addTarget:self action:@selector(ContinueInsButtonTap:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnInsuranceDetail];
    
    btnContinueInsuanceJiaoqiang=[UIButton buttonWithType:UIButtonTypeCustom];
    btnContinueInsuanceJiaoqiang.frame=CGRectMake(179, 425, 115, 30);
    [btnContinueInsuanceJiaoqiang setImage:[UIImage imageNamed:@"ContinueIns@2x.png"] forState:UIControlStateNormal];
    [btnContinueInsuanceJiaoqiang addTarget:self action:@selector(ContinueInsJiaoqiangButtonTap:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnInsuranceDetail];
    [self.view addSubview:btnContinueInsuance];
    [self.view addSubview:btnContinueInsuanceJiaoqiang];
    
    TableViewJiaoqiang = [[UITableView alloc]initWithFrame:CGRectMake(0, 250, self.view.frame.size.width, 165) style:UITableViewStyleGrouped];
	TableViewJiaoqiang.delegate = self;
	TableViewJiaoqiang.dataSource = self;
    TableViewJiaoqiang.opaque = NO;
    TableViewJiaoqiang.backgroundView = nil;
    TableViewJiaoqiang.autoresizingMask = UIViewContentModeTop;
    TableViewJiaoqiang.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewJiaoqiang.scrollEnabled=NO;
    [self.view addSubview:TableViewJiaoqiang];
    arrData=[[NSMutableArray alloc]init];
    [self getCarInfo];
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bContinueInsurance=FALSE;
    
    [self setEvaluationRequest];
}

-(void)getCarInfo
{
    RCCarListInfo *rcCarListInfo=[[RCCarListInfo alloc]initCarListInfoView];
    rcCarListInfo.carInfoDelegate=self;
    [rcCarListInfo setCarListRequest:YES];
    [rcCarListInfo setHidden:YES];
    [self.view addSubview:rcCarListInfo];
    [rcCarListInfo release];
}
-(void)getCarListInfo:(BOOL)bCarInfo
{
    
}
-(void)getCarDetailInfo
{
    [self setRequest];
}
-(void) ClickCallOutBtn
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    if (myDelegate.bContinueInsurance==FALSE) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        if ([Flag isEqualToString:@"0"])
        {
            [self IFServiceEvaluation];
            Flag = @"1";
        }
        else
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }

}

-(void)setEvaluationRequest
{
    NSLog(@"==================");
    NSString *serviceid =@"63101";
    NSString *servicename =@"我想续保";
    IFServiceEvaluation *ifserviceevaluation =[[IFServiceEvaluation alloc]initView:serviceid withserviceName:servicename];
    [ifserviceevaluation setIfServiceEvaluationRequest];
    [ifserviceevaluation setHidden:YES];
    [self.view addSubview:ifserviceevaluation];
    [ifserviceevaluation release];
}
-(void) IFServiceEvaluation
{
    NSString *serviceid =@"63101";
    NSString *servicename =@"我想续保";
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    if ([myDefaults stringForKey:serviceid]) {
        NSString *strEvaluate=[myDefaults stringForKey:serviceid];
        if ([strEvaluate isEqualToString:@"1"]) {
            AddServiceEvaluationViewController *serviceevluation = [[AddServiceEvaluationViewController alloc]initView:serviceid withserviceName:servicename];
            [[AppDelegate app].unc pushViewController:serviceevluation animated:YES];
            [serviceevluation release];
        }
        else
        {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

-(void)ClickExchangeHistoryBtn
{
    InsuranceHistoryViewController *insuranceHistoryViewCtrl=[[InsuranceHistoryViewController alloc]init];
    [self.navigationController pushViewController:insuranceHistoryViewCtrl animated:YES];
    [insuranceHistoryViewCtrl release];
}
-(void)InsDetailButtonTap:(id)sender
{
    SunInsuranceViewController *sunInsuranceViewCtrl=[[SunInsuranceViewController alloc]init];
    sunInsuranceViewCtrl.strPolicyNo=strBusinessPolicyNo;
    [self.navigationController pushViewController:sunInsuranceViewCtrl animated:YES];
    [sunInsuranceViewCtrl release];
}

-(void)ContinueInsButtonTap:(id)sender
{
    ApplyInsuranceViewController *applyInsuranceViewCtrl=[[ApplyInsuranceViewController alloc]init];
    applyInsuranceViewCtrl.strPolicyNo=strBusinessPolicyNo;
    [self.navigationController pushViewController:applyInsuranceViewCtrl animated:YES];
    [applyInsuranceViewCtrl release];
}

-(void)ContinueInsJiaoqiangButtonTap:(id)sender
{
    ApplyInsuranceViewController *applyInsuranceViewCtrl=[[ApplyInsuranceViewController alloc]init];
    applyInsuranceViewCtrl.strPolicyNo=strJiaoqiangPolicyNo;
    [self.navigationController pushViewController:applyInsuranceViewCtrl animated:YES];
    [applyInsuranceViewCtrl release];
}

#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    if (tableView==TableViewBusiness) {
        NSLog(@"循环前arrData:%@",arrData);
        NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
        
            for (int i=0; i<[arrData count]; i++) {
                //[dictItem removeAllObjects];
                dictItem=[arrData objectAtIndex:i];
                NSString *strProductCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"productCode"]];
                if ([strProductCode isEqualToString:@"11023800"]) {
                    ItemCountBusiness=[dictItem count];
                    break;
                }
                else
                {
                    //[dictItem removeAllObjects];
                }
                
            }
        if (ItemCountBusiness==0) {
            TableViewBusiness.hidden=YES;
            btnInsuranceDetail.hidden=YES;
            btnContinueInsuance.hidden=YES;
    
        }
        else
        {
            TableViewBusiness.hidden=NO;
            btnInsuranceDetail.hidden=NO;
            btnContinueInsuance.hidden=NO;
        }
        NSLog(@"商业险count:%d",ItemCountBusiness);
        return ItemCountBusiness;
    }
    else if(tableView==TableViewJiaoqiang)
    {
        NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
            for (int i=0; i<[arrData count]; i++) {
                //[dictItem removeAllObjects];
                dictItem=[arrData objectAtIndex:i];
                NSString *strProductCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"productCode"]];
                if ([strProductCode isEqualToString:@"11022400"]) {
                    ItemCountJiaoQiang=[dictItem count];
                    break;
                }else
                {
                    //[dictItem removeAllObjects];
                }
                
            }
        if (ItemCountJiaoQiang==0) {
            TableViewJiaoqiang.hidden=YES;
            btnContinueInsuanceJiaoqiang.hidden=YES;
            
        }
        else
        {
            if (ItemCountBusiness==0) {
                [TableViewJiaoqiang setFrame:CGRectMake(0, 44, self.view.frame.size.width, 165)];
                [btnContinueInsuanceJiaoqiang setFrame:CGRectMake(179, 215, 115, 30)];
            }
            else
            {
                [TableViewJiaoqiang setFrame:CGRectMake(0, 250, self.view.frame.size.width, 165)];
                [btnContinueInsuanceJiaoqiang setFrame:CGRectMake(179, 425, 115, 30)];
            }
            TableViewJiaoqiang.hidden=NO;
            btnContinueInsuanceJiaoqiang.hidden=NO;
        }
        NSLog(@"交强险count:%d",ItemCountJiaoQiang);
        return ItemCountJiaoQiang;
    }
    else
    {
        return 0;
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *Identifier=@"Identifier";
    UITableViewCell *cell=(UITableViewCell *)[TableViewBusiness dequeueReusableCellWithIdentifier:Identifier];
    if (cell==nil)
    {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    
    if (tableView==TableViewBusiness) {
         NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
        if ([arrData count]>0) {
            for (int i=0; i<[arrData count]; i++) {
                [dictItem removeAllObjects];
                dictItem=[arrData objectAtIndex:i];
                NSString *strProductCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"productCode"]];
                if ([strProductCode isEqualToString:@"11023800"]) {
                    break;
                }
                else
                {
                    [dictItem removeAllObjects];
                }
                
            }
        }
        NSString *strPolicyNo,*strStartDate,*strEndDate,*strInsuredName,*strApplyName,*strInsuredAmount,*strGrossPremium;
        if ([dictItem valueForKey:@"policyNo"]) {
           strPolicyNo=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"policyNo"]];
        }
        else
        {
            strPolicyNo=@"";
        }
        strBusinessPolicyNo=strPolicyNo;
        
        if ([dictItem valueForKey:@"startDate"]) {
            strStartDate=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"startDate"]];
        }
        else
        {
            strStartDate=@"";
        }
        
        if ([dictItem valueForKey:@"endDate"]) {
            strEndDate=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"endDate"]];
        }
        else
        {
            strEndDate=@"";
        }
        
        if ([dictItem valueForKey:@"insuredName"]) {
            strInsuredName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"insuredName"]];
        }
        else
        {
            strInsuredName=@"";
        }
        
        if ([dictItem valueForKey:@"applyName"]) {
            strApplyName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"applyName"]];
        }
        else
        {
            strApplyName=@"";
        }
        
        if ([dictItem valueForKey:@"insuredAmount"]) {
            strInsuredAmount=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"insuredAmount"]];
        }
        else
        {
            strInsuredAmount=@"";
        }
        
        
        if ([dictItem valueForKey:@"grossPremium"]) {
            strGrossPremium=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"grossPremium"]];
        }
        else
        {
            strGrossPremium=@"";
        }
        
        
        
        cell.textLabel.font=[UIFont systemFontOfSize:14.0];
        if (indexPath.row==0) {
            cell.textLabel.text=[NSString stringWithFormat:@"商业险:%@ 到 %@",strStartDate,strEndDate];
        }
        else if(indexPath.row==1)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"保单号:%@",strPolicyNo];
        }
        else if(indexPath.row==2)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"投保人:%@",strApplyName];
        }
        else if(indexPath.row==3)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"被保人:%@",strInsuredName];
        }
        else if(indexPath.row==4)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"保费:%@",strGrossPremium];
        }
        
//        [strPolicyNo release];
//        [strStartDate release];
//        [strEndDate release];
//        [strInsuredName release];
//        [strApplyName release];
//        [strInsuredName release];
//        [strApplyName release];
//        [strInsuredAmount release];
//        [strGrossPremium release];
    }
    else if(tableView==TableViewJiaoqiang)
    {
        NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
        if ([arrData count]>0) {
            for (int i=0; i<[arrData count]; i++) {
                [dictItem removeAllObjects];
                dictItem=[arrData objectAtIndex:i];
                NSString *strProductCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"productCode"]];
                if ([strProductCode isEqualToString:@"11022400"]) {
                    break;
                }else
                {
                    [dictItem removeAllObjects];
                }
                
            }
        }
        NSString *strPolicyNo,*strStartDate,*strEndDate,*strInsuredName,*strApplyName,*strInsuredAmount,*strGrossPremium;
        if ([dictItem valueForKey:@"policyNo"]) {
            strPolicyNo=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"policyNo"]];
        }
        else
        {
            strPolicyNo=@"";
        }
        strJiaoqiangPolicyNo=strPolicyNo;
        
        if ([dictItem valueForKey:@"startDate"]) {
            strStartDate=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"startDate"]];
        }
        else
        {
            strStartDate=@"";
        }
        
        if ([dictItem valueForKey:@"endDate"]) {
            strEndDate=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"endDate"]];
        }
        else
        {
            strEndDate=@"";
        }
        
        if ([dictItem valueForKey:@"insuredName"]) {
            strInsuredName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"insuredName"]];
        }
        else
        {
            strInsuredName=@"";
        }
        
        if ([dictItem valueForKey:@"applyName"]) {
            strApplyName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"applyName"]];
        }
        else
        {
            strApplyName=@"";
        }
        
        if ([dictItem valueForKey:@"insuredAmount"]) {
            strInsuredAmount=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"insuredAmount"]];
        }
        else
        {
            strInsuredAmount=@"";
        }
        
        
        if ([dictItem valueForKey:@"grossPremium"]) {
            strGrossPremium=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"grossPremium"]];
        }
        else
        {
            strGrossPremium=@"";
        }
        
        cell.textLabel.font=[UIFont systemFontOfSize:14.0];
        if (indexPath.row==0) {
            cell.textLabel.text=[NSString stringWithFormat:@"交强险:%@ 到 %@",strStartDate,strEndDate];
        }
        else if(indexPath.row==1)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"保单号:%@",strPolicyNo];
        }
        else if(indexPath.row==2)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"投保人:%@",strApplyName];
        }
        else if(indexPath.row==3)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"被保人:%@",strInsuredName];
        }
        else if(indexPath.row==4)
        {
            cell.textLabel.text=[NSString stringWithFormat:@"保费:%@",strGrossPremium];
        }
        
//        [strPolicyNo release];
//        [strStartDate release];
//        [strEndDate release];
//        [strInsuredName release];
//        [strApplyName release];
//        [strInsuredName release];
//        [strApplyName release];
//        [strInsuredAmount release];
//        [strGrossPremium release];
    
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

-(void)setRequest//向太保移动平台发送请求报文
{
    Flag=@"0";
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    
    
    NSUserDefaults *myDefaultsCarInfo=[NSUserDefaults standardUserDefaults];
    NSDictionary *dictCarInfo=[myDefaultsCarInfo dictionaryForKey:DICT_CAR_CUSTOMERINFO];
    if (dictCarInfo!=nil)
    {
        if ([dictCarInfo valueForKey:@"license"])
        {
            NSString *strLincense=[dictCarInfo valueForKey:@"license"];
            if ([strLincense isEqualToString:@""]) {
                [self justShowMessage:@"车牌号码为空,请到车辆设置页面去补充" title:@"注意"];
                return;
            }
        }else{
            [self justShowMessage:@"车牌号码为空,请到车辆设置页面去补充" title:@"注意"];
            return;
        }
        if ([dictCarInfo valueForKey:@"iDNum"]) {
            NSString *strIDNum=[dictCarInfo valueForKey:@"iDNum"];
            if ([strIDNum isEqualToString:@""]) {
                [self justShowMessage:@"证件号码号码为空,请到车辆设置页面去补充" title:@"注意"];
                return;
            }
        }else
        {
            [self justShowMessage:@"证件号码为空,请到车辆设置页面去补充" title:@"注意"];
            return;
        }
        if ([dictCarInfo valueForKey:@"policyHolder"]) {
            NSString *strPolicyHolder=[dictCarInfo valueForKey:@"policyHolder"];
            if ([strPolicyHolder isEqualToString:@""]) {
                [self justShowMessage:@"投保人为空,请到车辆设置页面去补充" title:@"注意"];
                return;
            }
        }else
        {
            [self justShowMessage:@"投保人为空,请到车辆设置页面去补充" title:@"注意"];
            return;
        }
    }
    else
    {
        [self justShowMessage:@"资料不完整,请到车辆设置页面去补充" title:@"注意"];
        return;
    }

    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    [dicRequest setObject:[dictUserInfo valueForKey:@"UserAccount"] forKey:@"userAccount"];
    [dicRequest setObject:[dictCarInfo valueForKey:@"policyHolder"] forKey:@"userName"];
    [dicRequest setObject:[dictCarInfo valueForKey:@"iDNum"] forKey:@"idNo"];
    [dicRequest setObject:[dictCarInfo valueForKey:@"license"] forKey:@"license"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];

    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"63101" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress) {
        NSLog(@"88888");
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"查询中...";
        [progress show:YES];
        showProgress = NO;
    };
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==1) {
        if (buttonIndex==0) {
            [self.navigationController popToRootViewControllerAnimated:YES];
            return;
        }
    }
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictAppointmentList=[dictResponse objectForKey:@"renewPolicyList"];
 
    
    arrData=[dictAppointmentList valueForKey:@"data"];
    NSLog(@"arrData:%@",arrData);
    if ([arrData count]>0) {
        [TableViewBusiness reloadData];
        [TableViewJiaoqiang reloadData];
    }else
    {
        [self justShowMessage:@"保单数据为空" title:@"注意"];
    }
    
    NSString *Code =@"63101";
    OperationLogView *operationlog =[[OperationLogView alloc]initView:Code withtype:@"1" withserialno:@""];
    [operationlog setOperationLogRequest];
    [operationlog setHidden:YES];
    [self.view addSubview:operationlog];
    [operationlog release];
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)dealloc
{
    [arrData release];
    [super dealloc];
}

@end
